package com.droid.network.interceptor;

import android.content.Context;

import com.droid.network.base.INetworkRequiredInfo;

import java.io.IOException;

import androidx.annotation.NonNull;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @author zhyuc
 * @since 2019/9/24 18:48
 */
public class CommonRequestInterceptor implements Interceptor {

    private Context context;
    private INetworkRequiredInfo requiredInfo;

    public CommonRequestInterceptor(Context context, @NonNull INetworkRequiredInfo requiredInfo) {
        this.context = context;
        this.requiredInfo = requiredInfo;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request.Builder builder = chain.request().newBuilder();
        builder.header("Connection", "close");
        /*if (context != null) {
            HashSet<String> preferences = (HashSet) context.getSharedPreferences(PersistentCookieStore.COOKIE_PREFS, Context.MODE_PRIVATE)
                    .getStringSet(chain.request().url().host(), new HashSet<>());
            for (String cookie : preferences) {
                builder.addHeader(requiredInfo.getCookieName(), cookie);
                // This is done so I know which headers are being added; this interceptor is used after the normal logging of OkHttp
                Log.d("OkHttp", "Adding Header: " + cookie);
            }
        }*/
        return chain.proceed(builder.build());
    }
}
